home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3104 < prev    next >
Encoding:
Text File  |  1996-08-05  |  8.6 KB  |  368 lines

  1. Path: meenie.Princeton.EDU!john
  2. From: john@meenie.Princeton.EDU (John Saponara)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Need amiga-specific docs to solve BGUI problem? (LONG)
  5. Date: 12 Feb 1996 03:48:32 GMT
  6. Organization: Princeton University
  7. Distribution: world
  8. Message-ID: <4fmdag$1i2@cnn.Princeton.EDU>
  9. Reply-To: john@meenie.Princeton.EDU (John Saponara)
  10. NNTP-Posting-Host: meenie.princeton.edu
  11. Originator: john@meenie
  12.  
  13.  
  14. Hi folks,
  15.  
  16. I am having trouble changing attribute values of BGUI gadgets.
  17. I understand there is documentation available for programming
  18. the amiga.  My questions thus are two:
  19.  
  20. 1. How does one get amiga-specific programming docs?
  21.    Are they available in online form?
  22.  
  23. 2. Below I list code that attempts to use the SetAttrs and
  24.    SetGadgetAttrs calls to change label text or indicator
  25.    value in several kinds of gadgets.  Neither SetAttrs nor
  26.    SetGadgetAttrs affect the gadget contents, tho SetGadgetAttrs
  27.    freezes the mouse pointer briefly.  Is my error apparent
  28.    from this code?
  29.  
  30. Thanks very much for any suggestions,
  31. John Saponara
  32.  
  33. /********************* test.c ********************/
  34.  
  35. #include "democode.h"    /* listed below */
  36.  
  37. /*
  38. **  One, shared, message port for all
  39. **  demo windows.
  40. **/
  41. struct MsgPort  *SharedPort;
  42.  
  43. /*
  44. **  Menus & gadget ID's.
  45. **/
  46. #define ID_QUIT         2L
  47. #define ID_INPUT    3L
  48.  
  49. /*
  50. **  Notification map-lists.
  51. **/
  52. ULONG  sl2in [] = { SLIDER_Level,  INDIC_Level,   TAG_END };
  53.  
  54. /*
  55. **  Window objects.
  56. **/
  57. Object    *WA_Main  = NULL;
  58.  
  59. /*
  60. **  Gadget objects from the main window.
  61. **/
  62.  
  63. Object* quitButton;
  64. Object* inputSlider;
  65.  
  66. /*
  67.   These are the `output' gadgets whose displayed value
  68.   I try to change in the Update function below.
  69. */
  70. Object* outputIndicator;
  71. Object* outputInfo;
  72. Object* outputString;
  73. Object* outputButton;
  74.  
  75. /*
  76. **  Open main window.
  77. **/
  78. struct Window *OpenMainWindow( ULONG *appmask )
  79. {
  80.   struct Window    *window = NULL;
  81.  
  82.   WA_Main = WindowObject,
  83.     WINDOW_Title,      "testing BGUI",
  84.     WINDOW_ScaleWidth,      100,
  85.     WINDOW_SmartRefresh,  TRUE,
  86.     WINDOW_SharedPort,    SharedPort,
  87.     WINDOW_MasterGroup,
  88.     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  89.       StartMember, inputSlider = HorizSlider(  "input", 0, 12, 0, ID_INPUT ), EndMember,
  90.       StartMember, quitButton   = XenKeyButton( "Quit",  ID_QUIT  ), EndMember,
  91.       /*
  92.         Set up several kinds of gadgets for attempted output.
  93.       */
  94.       StartMember, outputIndicator = IndicatorFormat( 0, 12, 0, IDJ_RIGHT, "%ld" ), EndMember,
  95.       StartMember, outputInfo   = InfoObject, INFO_TextFormat,    ISEQ_C "info", EndObject, EndMember,
  96.       StartMember, outputString = StringObject, LAB_Label, "string", EndObject, EndMember,
  97.       StartMember, outputButton = ButtonObject, LAB_Label, "button", EndObject, EndMember,
  98.     EndObject,
  99.   EndObject;
  100.  
  101.   /*
  102.   **  Object created OK?
  103.   **/
  104.   if ( WA_Main ) {
  105.  
  106.     /*
  107.     **  Could connect slider to indicator, but instead I want to
  108.     **  do a calculation with the slider value and display some result.
  109.     **  See Update function below.
  110.     **/
  111.  
  112.     /* AddMap( inputSlider, outputIndicator, sl2in ); */
  113.  
  114.     /*
  115.     **  Open the window.
  116.     **/
  117.  
  118.     window = WindowOpen( WA_Main );
  119.   }
  120.  
  121.   return( window );
  122. }
  123.  
  124. /*
  125.   The following function, Update, is called in StartDemo (below)
  126.   every time the user clicks on the slider.
  127. */
  128.  
  129. void Update( void )
  130. {
  131.   static long num = 0;
  132.  
  133.   puts( "Reached update function.\n" );
  134.  
  135.   /*
  136.     The following SetAttrs lines do nothing.
  137.     Shouldn't they change the gadget's value?
  138.   */
  139.  
  140.   SetAttrs( outputIndicator, INDIC_Level,     num++,         TAG_END );
  141.   SetAttrs( outputString,    LAB_Label,       "new!",        TAG_END );
  142.   SetAttrs( outputButton,    LAB_Label,       "new!",        TAG_END );
  143.   SetAttrs( outputInfo,      INFO_TextFormat, ISEQ_C "new!", TAG_END );
  144.  
  145.   /*
  146.     The following SetGadgetAttrs lines freeze the mouse for a moment,
  147.     but don't change the gadget's value.
  148.   */
  149.  
  150.   /* SetGadgetAttrs(
  151.     ( struct Gadget * )outputIndicator,
  152.     WA_Main, NULL, INDIC_Level, num++, TAG_END ); */
  153.   /* SetGadgetAttrs(
  154.     ( struct Gadget * )outputString,
  155.     WA_Main, NULL, LAB_Label, "new!", TAG_END ); */
  156.   /* SetGadgetAttrs(
  157.     ( struct Gadget * )outputButton,
  158.     WA_Main, NULL, LAB_Label, "new!", TAG_END ); */
  159.   /* SetGadgetAttrs(
  160.     ( struct Gadget * )outputInfo,
  161.     WA_Main, NULL, INFO_TextFormat, ISEQ_C "new!", TAG_END ); */
  162. }
  163.  
  164. long value;
  165.  
  166. /*
  167. **  Main entry.
  168. **/
  169. VOID StartDemo( void )
  170. {
  171.   struct Window *main = NULL, *sigwin = ( struct Window * )~0;
  172.   ULONG sigmask = 0L, sigrec, rc, appsig = 0L;
  173.   BOOL running = TRUE;
  174.  
  175.   /*
  176.   **  Create the shared message port.
  177.   **/
  178.   if ( SharedPort = CreateMsgPort()) {
  179.     /*
  180.     **  Open the main window.
  181.     **/
  182.     if ( main = OpenMainWindow( &appsig )) {
  183.       /*
  184.       **  OR signal masks.
  185.       **/
  186.       sigmask |= ( appsig | ( 1L << SharedPort->mp_SigBit ));
  187.       /*
  188.       **  Loop...
  189.       **/
  190.       do {
  191.         /*
  192.         **  Wait for the signals to come.
  193.         **/
  194.         sigrec = Wait( sigmask );
  195.  
  196.         /*
  197.         **  Find out which window signalled us.
  198.         **/
  199.         if ( sigrec & ( 1 << SharedPort->mp_SigBit )) {
  200.           while ( sigwin = GetSignalWindow( WA_Main )) {
  201.  
  202.             /*
  203.             **  Main window signal?
  204.             **/
  205.             if ( sigwin == main ) {
  206.               /*
  207.               **  Call the main-window event handler.
  208.               **/
  209.               while (( rc = HandleEvent( WA_Main )) != WMHI_NOMORE ) {
  210.                 switch ( rc ) {
  211.  
  212.                   case  WMHI_CLOSEWINDOW:
  213.                   case  ID_QUIT:
  214.                     running = FALSE;
  215.                     break;
  216.  
  217.                   case ID_INPUT:
  218.                     /*
  219.                       At each slider input, print value and
  220.                       call Update to try changing output gadgets.
  221.                     */
  222.                     GetAttr( SLIDER_Level, inputSlider, &value );
  223.                     printf( "value=%ld\n", value );
  224.                     Update();
  225.                     break;
  226.                 }
  227.               }
  228.             }
  229.           }
  230.         }
  231.       } while ( running );
  232.     }
  233.     /*
  234.     **  Dispose of all window objects.
  235.     **/
  236.     if ( WA_Main )    DisposeObject( WA_Main );
  237.     /*
  238.     **  Delete the shared message port.
  239.     **/
  240.     DeleteMsgPort( SharedPort );
  241.   } else
  242.     Tell( "Unable to create a message port.\n" );
  243. }
  244.  
  245. /********************* democode.h ********************/
  246.  
  247. /*
  248.  *  DEMOCODE.H
  249.  *
  250.  *  (C) Copyright 1995 Jaba Development.
  251.  *  (C) Copyright 1995 Jan van den Baard.
  252.  *      All Rights Reserved.
  253.  */
  254.  
  255. #include <exec/types.h>
  256. #include <exec/memory.h>
  257. #include <dos/dos.h>
  258. #include <libraries/gadtools.h>
  259. #include <libraries/bgui.h>
  260. #include <libraries/bgui_macros.h>
  261. #include <intuition/sghooks.h>
  262. #include <graphics/gfxmacros.h>
  263. #include <workbench/workbench.h>
  264. #include <workbench/startup.h>
  265.  
  266. #include <clib/alib_protos.h>
  267.  
  268. #include <proto/exec.h>
  269. #include <proto/intuition.h>
  270. #include <proto/dos.h>
  271. #include <proto/bgui.h>
  272. #include <proto/graphics.h>
  273. #include <proto/diskfont.h>
  274.  
  275. #include <stdlib.h>
  276.  
  277. #ifdef _DCC
  278. #define SAVEDS __geta4
  279. #define ASM
  280. #define REG(x) __ ## x
  281. #define CHIP(t) __chip t
  282. #else
  283. #define SAVEDS __saveds
  284. #define ASM __asm
  285. #define REG(x) register __ ## x
  286. #define CHIP(t) t chip
  287. #endif
  288.  
  289. /*
  290.  *  The entry point of all demo programs.
  291.  */
  292. extern VOID StartDemo( void );
  293.  
  294. /*
  295.  *  Output file handle and BGUI
  296.  *  library base.
  297.  */
  298. BPTR    StdOut;
  299. struct Library *BGUIBase;
  300.  
  301. /*
  302.  *  Output text to the CLI or Workbench console.
  303.  */
  304. VOID Tell( UBYTE *fstr, ... )
  305. {
  306.   if ( StdOut ) VFPrintf( StdOut, fstr, ( ULONG * )&fstr + 1 );
  307. }
  308.  
  309. /*
  310.  *  Main entry point.
  311.  */
  312. int main( int argc, char **argv )
  313. {
  314.   struct Process      *this_task = ( struct Process * )FindTask( NULL );
  315.   BOOL         is_wb = FALSE;
  316.  
  317.   if ( this_task->pr_CLI )
  318.     /*
  319.      *  Started from the CLI. Simply pickup
  320.      *  the CLI output handle.
  321.      */
  322.     StdOut = Output();
  323.   else {
  324.     /*
  325.      *  Workbench startup. Open a console
  326.      *  for output.
  327.      */
  328.     StdOut = Open( "CON:10/10/500/100/BGUI Demo Output/WAIT/AUTO", MODE_NEWFILE );
  329.     is_wb = TRUE;
  330.   }
  331.  
  332.   /*
  333.    *  Open BGUI.
  334.    */
  335.   if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  336.     /*
  337.      *  Run the demo.
  338.      */
  339.     StartDemo();
  340.     CloseLibrary( BGUIBase );
  341.   } else
  342.     Tell( "Unable to open %s version %ld\n", BGUINAME, BGUIVERSION );
  343.  
  344.   /*
  345.    *  Close console if ran from
  346.    *  the workbench.
  347.    */
  348.   if ( is_wb ) {
  349.     if ( StdOut ) Close( StdOut );
  350.   }
  351.  
  352.   return( 0 );
  353. }
  354.  
  355. /*
  356.  *  DICE stub which simply calls
  357.  *  main() when run from the
  358.  *  workbench.
  359.  */
  360. #ifdef _DCC
  361. int wbmain( struct WBStartup *wbs )
  362. {
  363.   return( main( NULL, 0 ));
  364. }
  365. #endif
  366.  
  367. /********************* end of post ********************/
  368.